package demo1;

import java.util.InputMismatchException;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        try {
            int result = readInteger();
            System.out.println("你输入的整数是: " + result);
        } catch (InputMismatchException e) {
            System.out.println("输入有误，请输入一个有效的整数。");
        }
        int result = readInteger();
        System.out.println("你输入的整数是: " + result);
    }

    public static int readInteger() throws InputMismatchException {
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入一个整数: ");
        return scanner.nextInt();
    }
}
